import requests
import random
import redis


def save_request_url(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    client.lpush('leave4', url)
    client.close()

def get_requested_urls(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    urls = client.lrange('leave4', 0, -1)
    client.close()
    return url.encode() in urls


urls = [f'https://httpbin.org/get?age={random.randint(1,100)}'for i in range(10)]
for url in urls:
    if not get_requested_urls(url):
        res = requests.get(url)
        print(res)
        save_request_url(url)
    else:
        print('已爬取过')

